package com.frejoys.dao.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.frejoys.common.dto.admin.UserListDto;
import com.frejoys.common.dto.admin.UserNameAndPhoneDto;
import com.frejoys.common.vo.admin.AdminListVo;
import com.frejoys.common.vo.admin.UserAgentVo;
import com.frejoys.common.vo.admin.UserVo;
import com.frejoys.dao.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@InterceptorIgnore(dataPermission = "true")
public interface UserMapper extends BaseMapper<User> {

    ////查询用户 头像昵称
    List<User> getUserList(@Param("userIds") List<Long> userIds ,@Param("status") Integer status);

    @InterceptorIgnore(dataPermission = "false")
    @Select("select * from user")
    List<User> getList();


    /**
     *
     * @param userId 用户id
     * @param role 角色
     * @param status 状态
     * @return
     */
    @Select("select id from j_user where id = #{userId} and role & #{role} and status =#{status}")
    Long getCount(@Param("userId") Long userId,@Param("role") Integer role,@Param("status") Integer status);
    /**
     * 只查询用户状态和角色
     * @param userId
     */
    @Select("select id,role,status from j_user where id = #{userId}")
    User getSimpleUser(@Param("userId") Long userId);


    /**
     * 只查询用户状态和角色
     * @param userIds
     */
    List<User> getSimpleListUser(@Param("userIds") List<Long> userIds);

    /**
     * 只查询用户名称和电话和头像
     * @param userIds
     */
    List<User> getUserByIds(@Param("userIds") List<Long> userIds);
    /**
     * 获取用户nickname
     */
    @Select("select nickname from j_user where id = #{userId} and status = #{status}")
    String getNickname(@Param("userId") Long userId,@Param("status") Integer status);

    /**
     * 获取用户名字和电话
     */
    @Select("select id,nickname,phone from j_user where id = #{userId}")
    User getNicknameAndPhone(@Param("userId") Long userId);

    //查询代理人列表信息
    Page<UserAgentVo> agentListInfo(@Param("page") Page page,@Param("role") Integer role,@Param("status") Integer status,@Param("nickname") String nickname,@Param("phone") String phone);

    //根据电话号查询userId
    @Select("select id from j_user where phone = #{phone}")
    Long phoneByUserId(@Param("phone") String phone);

    //根据用户名昵称查询userId
    @Select("select id from j_user where nickname like concat('%',#{nickname},'%')")
    List<Long> nicknameByUserId(@Param("nickname") String nickname);

    //查询商家列表
    IPage<UserVo> getStoreUserList(@Param("page") Page page, @Param("dto") UserListDto dto, @Param("role") Integer role);

    //后台查询用户列表
    IPage<User> listUser(@Param("page") Page page,@Param("dto") UserListDto dto);

    IPage<AdminListVo> adminList(@Param("page") Page page, @Param("dto") UserNameAndPhoneDto dto, @Param("role") Integer role);
}
